import threading

from flask import request
from flask_restful import Resource

from utils.little.we_sql import update_user_form

lock = threading.Lock()


class we_update_api(Resource):

    def post(self):
        """
        上传表单
        :return: 1:成功,2:非法参数,3:失败,4:学号已存在
        """
        form = request.form
        student_num = form.get("student_num")

        try:
            student_num = int(student_num)
        except ValueError:
            return '2'

        username = form.get("name")
        sex = form.get("sex")
        conn = form.get("connect")
        desc = form.get("desc")

        with lock:
            num = update_user_form(student_num, username, sex, conn, desc)

        return num
